﻿using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
using MaxStoreShop.Domain.Directories;

namespace MaxStoreShop.Logic.Validators
{
    public class ProductCategoryValidator : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            var bindingGroup = value as BindingGroup;
            if (bindingGroup == null)
                return new ValidationResult(false, "Строка для проверки не является BindingGroup!");

            if (bindingGroup.Items == null || bindingGroup.Items.Count == 0)
                return ValidationResult.ValidResult;

            var productCategory = bindingGroup.Items[0] as ProductCategory;
            if (productCategory == null)
                return new ValidationResult(false, "Строка для проверки не является ProductCategory!");

            if (string.IsNullOrWhiteSpace(productCategory.Name))
                return new ValidationResult(false, "Наименование категории продуктов не должно быть пустым!");

            return ValidationResult.ValidResult;
        }
    }
}
